home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-03 | 4.6 KB | 135 lines | [TEXT/MPS ] |
- {
- File: ThreadUtil.p
-
- Contains: External Interface to Thread Manager Utilities
-
- Written by: Brad Post, Eric Anderson and Bill Knott
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 4/19/93 bsp Added the busy : Boolean into the LinkedList model
- 3/3/93 bsp Added the lastInList element to the LinkedListSemaphore model.
- 2/12/93 whk Converted Interfaces.
- 1/31/93 ewa New Today.
-
- }
-
- {$IFC UNDEFINED UsingIncludes}
- {$SETC UsingIncludes := 0}
- {$ENDC}
-
- {$IFC NOT UsingIncludes}
- UNIT ThreadUtil;
- INTERFACE
- {$ENDC}
-
- {$IFC UNDEFINED UsingThreadUtil}
- {$SETC UsingThreadUtil := 1}
-
- {$I+}
- {$SETC ThreadUtilIncludes := UsingIncludes}
- {$SETC UsingIncludes := 1}
- {$IFC UNDEFINED UsingTimer}
- {$I $$Shell(PInterfaces)Timer.p}
- {$ENDC}
- {$IFC UNDEFINED UsingThreads}
- {$I $$Shell(PInterfaces)Threads.p}
- {$ENDC}
- {$SETC UsingIncludes := ThreadUtilIncludes}
-
- { Constant Definitions }
-
- {--------------------------------------------------------------------------------}
- { Here are some of the error codes that can be returned. }
- {--------------------------------------------------------------------------------}
-
- CONST
- semaphoreButtHeadErr = 1;
- semaphoreWaitErr = 2;
-
- TYPE
- {--------------------------------------------------------------------------------}
- { These typedefs are used only by the SimpleSemaphore model. }
- {--------------------------------------------------------------------------------}
-
- SimpleSemaphorePtr = ^SimpleSemaphore;
- SimpleSemaphore = BOOLEAN;
-
- {--------------------------------------------------------------------------------}
- { These typedefs and structs are used only by the LinkedList Semaphore model. }
- {--------------------------------------------------------------------------------}
-
- LinkedListElementPtr = ^LinkedListElement;
- LinkedListElement = RECORD
- whoAmI : ThreadID;
- next : LinkedListElementPtr;
- END;
-
-
- LinkedListSemaphorePtr = ^LinkedListSemaphore;
- LinkedListSemaphore = RECORD
- available : Boolean;
- busy : Boolean;
- theHolder : ThreadID;
- waitingList : LinkedListElementPtr;
- lastInList : LinkedListElementPtr;
- END;
-
- {--------------------------------------------------------------------------------}
- { These typedefs and structs are only used by the Array Semaphore model. }
- {--------------------------------------------------------------------------------}
-
- ArraySemaphorePtr = ^ArraySemaphore;
- ArraySemaphore = RECORD
- available : Boolean;
- theHolder : ThreadID;
- whoseNext : LONGINT;
- nextSpot : LONGINT;
- numberWaiting : LONGINT;
- maxInQueue : LONGINT;
- waitList : ARRAY [0..0] OF ThreadID;
- END;
-
- { Routine Definitions }
-
- {--------------------------------------------------------------------------------}
- { Routine prototypes. }
- {--------------------------------------------------------------------------------}
-
- PROCEDURE DelayThread(millisecDelay : LONGINT);
-
- {--------------------------------------------------------------------------------}
- { These are the rountines for using Simple Semaphores. }
- {--------------------------------------------------------------------------------}
-
- FUNCTION CreateSimpleSemaphore(VAR aSemaphore : SimpleSemaphorePtr) : OSErr;
- FUNCTION GetSimpleSemaphore(aSemaphore : SimpleSemaphorePtr) : OSErr;
- FUNCTION ReleaseSimpleSemaphore(aSemaphore : SimpleSemaphorePtr) : OSErr;
- FUNCTION DeleteSimpleSemaphore(aSemaphore : SimpleSemaphorePtr) : OSErr;
-
- {--------------------------------------------------------------------------------}
- { These are the rountines for using LinkedList Semaphores. }
- {--------------------------------------------------------------------------------}
-
- FUNCTION CreateLinkedListSemaphore(VAR aSemaphore : LinkedListSemaphorePtr) : OSErr;
- FUNCTION GetLinkedListSemaphore(VAR whichOne : LinkedListElement; aSemaphore : LinkedListSemaphorePtr) : OSErr;
- FUNCTION ReleaseLinkedListSemaphore(aSemaphore : LinkedListSemaphorePtr) : OSErr;
- FUNCTION DeleteLinkedListSemaphore(aSemaphore : LinkedListSemaphorePtr) : OSErr;
-
- {--------------------------------------------------------------------------------}
- { These are the rountines for using Array Semaphores. }
- {--------------------------------------------------------------------------------}
-
- FUNCTION CreateArraySemaphore(maxInQueue : LONGINT; VAR aSemaphore : ArraySemaphorePtr) : OSErr;
- FUNCTION GetArraySemaphore(aSemaphore : ArraySemaphorePtr) : OSErr;
- FUNCTION ReleaseArraySemaphore(aSemaphore : ArraySemaphorePtr) : OSErr;
- FUNCTION DeleteArraySemaphore(aSemaphore : ArraySemaphorePtr) : OSErr;
-
- {$ENDC} { UsingThreadUtil }
-
- {$IFC NOT UsingIncludes}
- END.
- {$ENDC}
-